package com.xxx.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xxx.bean.Course;
import com.xxx.bean.Student;
import com.xxx.dao.StudentDAO;

public class StudentDaoImpl extends HibernateDaoSupport  implements StudentDAO {

	public void delete(Student student) throws Exception {
		getHibernateTemplate().delete(student);

	}

	public List<Student> findAll() throws Exception {
		String hql="FROM Student";
		List<Student> stuList=getHibernateTemplate().find(hql);
		return stuList;
	}

	public void save(Student student) throws Exception {
		
         getHibernateTemplate().save(student);
	}

	public void update(Student student) throws Exception {
		getHibernateTemplate().update(student);
	}

	public Student findById(int id) throws Exception {
		String hql="FROM Student WHERE id=?";
		Student student=(Student)getHibernateTemplate().find(hql, id).get(0);
		return student;
	}

	public Student findBySno(int sno) throws Exception {
		String hql="FROM Student WHERE sno=?";
		Student student=(Student)getHibernateTemplate().find(hql, sno).get(0);
		return student;
	}

	public void delScr(Student s, Course c) throws Exception {
	
		s.getCourses().remove(c);
		c.getStudents().remove(s);
		getHibernateTemplate().update(s);
		
	}
	

}
